package com.example.dingzexi_homework1;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TabLayout tabLayout = findViewById(R.id.tabs);
        ViewPager2 viewPager = findViewById(R.id.view_pager);

        TabAdapter tabAdapter = new TabAdapter(getSupportFragmentManager(), getLifecycle());
        viewPager.setAdapter(tabAdapter);

        new TabLayoutMediator(tabLayout, viewPager,
                (tab, position) -> tab.setText("Tab " + (position + 1)) // 设置每个Tab的文字
        ).attach();

        // 设置Tab的文字
        tabLayout.getTabAt(0).setText("首页");
        tabLayout.getTabAt(1).setText("好友");
        tabLayout.getTabAt(2).setText("我的");
        tabLayout.getTabAt(3).setText("创作");

    }
}